using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Data;
using InfraStructureLayer;

namespace WebControls
{
    public class SFMenu : Menu,IMultiLanguage
    {
        public SFMenu()
        {
            this.SkipLinkText = "";
        }
        #region IMultiLanguage Members

        public void SetControlLanguage()
        {
            this.Items.Clear();
            foreach (DataRow dr in CurrentContext.Menu.Select("LanguageId=" + CurrentContext.LanguageId.ToString() + " AND ParentMenuId IS NULL"))
            {
                if (!Convert.ToBoolean(dr["IsAdminMenu"]) || CurrentContext.UserId != null)
                {
                    MenuItem mi = new MenuItem();
                    mi.Text = dr["MenuText"].ToString();
                    mi.NavigateUrl = dr["NavigateUrl"].ToString();
                    mi.Value = dr["MenuId"].ToString();

                    if (this.Page.ResolveUrl(mi.NavigateUrl) == this.Page.Request.Url.AbsolutePath)
                    {
                        ((SFLabel)StaticMethods.FindControlRecursive(this.Page.Master, "lblHeader")[0]).Text = mi.Text;
                    }

                    this.Items.Add(mi);
                    SetControlsSub(mi, Convert.ToInt32(dr["MenuId"]));

                    MenuItem miSeperator = new MenuItem();
                    miSeperator.Text = "  |  ";
                    this.Items.Add(miSeperator);
                }
            }
            this.Items.RemoveAt(this.Items.Count - 1);
        }
        private void SetControlsSub(MenuItem miParent, int MenuItemId)
        {
            foreach (DataRow dr in CurrentContext.Menu.Select("LanguageId=" + CurrentContext.LanguageId.ToString() + " AND ParentMenuId=" + MenuItemId.ToString()))
            {
                if (!Convert.ToBoolean(dr["IsAdminMenu"]) || CurrentContext.UserId != null)
                {
                    MenuItem mi = new MenuItem();
                    mi.Text = dr["MenuText"].ToString();
                    mi.NavigateUrl = dr["NavigateUrl"].ToString();
                    mi.Value = dr["MenuId"].ToString();
                    SetControlsSub(mi, Convert.ToInt32(dr["MenuId"]));
                    miParent.ChildItems.Add(mi);
                    if (this.Page.ResolveUrl(mi.NavigateUrl) == this.Page.Request.Url.AbsolutePath)
                    {
                        ((SFLabel)StaticMethods.FindControlRecursive(this.Page.Master, "lblHeader")[0]).Text = mi.Parent.Text + " > " + mi.Text;
                    }
                }
            }
        }
        private bool _IsProtectedForLanguageChange = false;
        public bool IsProtectedForLanguageChange
        {
            get
            {
                return _IsProtectedForLanguageChange;
            }
            set
            {
                _IsProtectedForLanguageChange = value;
            }
        }

        private bool _IsMasterPageControl = false;
        public bool IsMasterPageControl
        {
            get
            {
                return _IsMasterPageControl;
            }
            set
            {
                _IsMasterPageControl = value;
            }
        }

        #endregion
    }
}
